package utils

import (
	"github.com/360EntSecGroup-Skylar/excelize"
	"income/model"
)

type Table struct {
	Employee  model.Employee
	Income    model.Income
	Company   string
	WorkMonth string
	SendDate  string
}

func GetTableList() (lists []Table) {
	var (
		employee *model.Employee
		income   *model.Income
		table    Table
	)
	xlsx, err := excelize.OpenFile("data/income.xlsx")
	if err != nil {
		Logger.Println(err)
		return
	}

	company := xlsx.GetCellValue("Sheet1", "C2")
	workday := xlsx.GetCellValue("Sheet1", "K2")
	sendday := xlsx.GetCellValue("Sheet1", "R2")
	rows := xlsx.GetRows("Sheet1")
	for _, columns := range rows[4:] {
		employee = model.NewEmploye(columns[0], columns[1], columns[2], columns[3], columns[4])
		income = &model.Income{
			WordDays:        columns[5],
			RealWorkDays:    columns[6],
			SickDays:        columns[7],
			StoryDays:       columns[8],
			BaseSalary:      columns[9],
			KpiSalary:       columns[10],
			CommisionSalary: columns[11],
			OtherSalary:     columns[12],
			SickReduce:      columns[13],
			StoryReduce:     columns[14],
			LeaveReduce:     columns[15],
			OtherReduce:     columns[16],
			PreSendSalary:   columns[17],
			SociAlaccumulat: columns[18],
			PersonTax:       columns[19],
			SendSalray:      columns[20],
		}
		table.Company = company
		table.WorkMonth = workday
		table.SendDate = sendday
		table.Employee = *employee
		table.Income = *income

		Logger.Println("导入数据到结构体")
		lists = append(lists, table)
	}
	return
}
